$(document).ready(function(){
	
	$(".homeTab").click(function(){
		
		allHomeTabsClosed();
		$(this).parent().addClass("tabOpen");
		
		
		//HIDE CONTENT
		
		
		$("#loadingTab").show();
		$("#homeTabContent").hide();
			
			var tabClass = $(this).text().replace(" ", "");
			
			//AJAX TO GET HOME TAB CONTENT
				//HEADER
				//CONTENT
				//IMAGE
				//LINK TO READ MORE
				//SEE ALL (TRUE / FALSE)
				//LINK TO SEE ALL (IF TRUE)
			
			var delay = function() { displayHomeTabContent(tabClass); };
			
			setTimeout(delay, 800);
	});
	
	function allHomeTabsClosed()
	{
		$("#homeTabs > span").removeClass("tabOpen");
	}
});

function displayHomeTabContent(tabClass)
{
	$.ajax({
		type: "POST",
		url: "php/ajax/home/tabContent.php",
		data: "t=" + tabClass,
		success: function(obj)
		{
			var json = JSON.parse(obj);
			
			//SHOW CONTENT
			$("#homeNewsHeading").text(json.heading);
			
			
			$("#loadingTab").hide();
			$("#homeTabContent").show();
		}
	});
}

